<%--
  product_detail.jsp
  作用：商品详情页面，显示单个商品的详细信息、图片以及卖家联系方式。
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${product.name} - 商品详情</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/layout.css">
</head>
<body>

<div class="main-container">
    <%-- 引入侧边栏 --%>
    <jsp:include page="/WEB-INF/parts/sidebar.jsp" />

    <main class="content-area">
        <%-- 引入头部 --%>
        <jsp:include page="/WEB-INF/parts/header.jsp" />

        <%-- 显示操作结果消息 --%>
        <c:if test="${not empty successMessage}">
            <p class="success-message">${successMessage}</p>
        </c:if>
        <c:if test="${not empty errorMessage}">
            <p class="error-message">${errorMessage}</p>
        </c:if>

        <div class="product-detail-container">
            <div class="product-detail-image">
                <img src="${pageContext.request.contextPath}/uploads/product_images/${product.imageUrl}" alt="${product.name}">
            </div>
            <div class="product-detail-info">
                <h1>${product.name}</h1>
                <p class="detail-price">价格: <span>¥ ${product.price}</span></p>
                <div class="detail-description">
                    <h4>商品描述</h4>
                    <p>${product.description}</p>
                </div>
                <div class="detail-seller">
                    <h4>卖家信息</h4>
                    <p>卖家: ${product.seller.username}</p>
                    <p>联系电话: ${product.seller.phone}</p>
                </div>
                <div class="detail-actions">
                     <a href="${pageContext.request.contextPath}/buy?id=${product.id}" class="btn">立即购买</a>
                </div>
            </div>
        </div>

        <div class="message-section">
            <h3>给卖家留言</h3>
            <c:choose>
                <c:when test="${not empty sessionScope.user}">
                    <c:if test="${sessionScope.user.id != product.seller.id}">
                        <form action="${pageContext.request.contextPath}/user/sendMessage" method="post" class="message-form">
                            <input type="hidden" name="receiverId" value="${product.seller.id}">
                            <input type="hidden" name="productId" value="${product.id}">
                            <textarea name="content" placeholder="输入你的留言..." rows="4" required></textarea>
                            <button type="submit" class="btn">发送私信</button>
                        </form>
                    </c:if>
                    <c:if test="${sessionScope.user.id == product.seller.id}">
                        <p class="info-message">这是您的商品，无需给自己留言。</p>
                    </c:if>
                </c:when>
                <c:otherwise>
                    <p class="info-message">请 <a href="${pageContext.request.contextPath}/login.jsp">登录</a> 后再给卖家留言。</p>
                </c:otherwise>
            </c:choose>
        </div>

    </main>
</div>

</body>
</html> 